package org.neuedu.chapter06_0622.practice06;

public class Student {
    String name;
    int stuno;
    double grade;

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", stuno=" + stuno +
                ", grade=" + grade +
                '}';
    }

    public Student(String name, int stuno, double grade) {
        this.name = name;
        this.stuno = stuno;
        this.grade = grade;
    }

    public Student() {
    }

    public static void main(String[] args) {
        Student s1 = new Student("a",111,55);
        Student s2 = new Student("b",123,33);
        Student s3 = new Student("c",125,44);
        Student s4 = new Student("d",171,99);
        Student[] students = {s1, s2, s3, s4};
        s1.sortByGrade(students);

        for (Student student : students) {
            System.out.println(student);
        }
    }

    public void sortByGrade(Student[] students) {
        for (int i = 1; i < students.length; i++) {
            for (int j = 0; j < students.length - i; j++) {
                if (students[j].getGrade() < students[j + 1].getGrade()) {
                    Student temp = students[j];
                    students[j] = students[j + 1];
                    students[j + 1] = temp;
                }
            }
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getStuno() {
        return stuno;
    }

    public void setStuno(int stuno) {
        this.stuno = stuno;
    }

    public double getGrade() {
        return grade;
    }

    public void setGrade(double grade) {
        this.grade = grade;
    }
}
